package com.kgc.smbms.service.impl;

import com.kgc.smbms.mapper.SmbmsUserMapper;
import com.kgc.smbms.pojo.SmbmsUser;
import com.kgc.smbms.pojo.SmbmsUserExample;
import com.kgc.smbms.service.SmbmsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmbmsUserServiceImpl implements SmbmsUserService {

    //创建对应的mapper对象
    @Autowired
    private SmbmsUserMapper smbmsUserMapper;


    public List<SmbmsUser> selectUsers() {
        return smbmsUserMapper.selectByExample(null);
    }

    public SmbmsUser loginUser(String usercode, String userpassword) {
        //1.创建一个对应的查询条件
        SmbmsUserExample example = new SmbmsUserExample();
        SmbmsUserExample.Criteria criteria = example.createCriteria();

        //拼接查询条件
        criteria.andUsercodeEqualTo(usercode);
        criteria.andUserpasswordEqualTo(userpassword);

        //查询
        List<SmbmsUser> smbmsUsers = smbmsUserMapper.selectByExample(example);

        if(null != smbmsUsers && smbmsUsers.size() >0){
            return smbmsUsers.get(0);
        }
        //如果不符合条件就返回一个空对象
        return null;
    }
}
